package com.irdstudio.efp.rule.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.rule.service.facade.TaxIncomeTaxInfoService;
import com.irdstudio.efp.rule.service.dao.TaxIncomeTaxInfoDao;
import com.irdstudio.efp.rule.service.domain.TaxAgainstLawInfo;
import com.irdstudio.efp.rule.service.domain.TaxIncomeTaxInfo;
import com.irdstudio.efp.rule.service.vo.TaxIncomeTaxInfoVO;


/**
 * Service Impl: 收入纳税信息表服务实现
 * @author ligm
 * @date 2019-04-29 
 */
@Service("taxIncomeTaxInfoService")
public class TaxIncomeTaxInfoServiceImpl implements TaxIncomeTaxInfoService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(TaxIncomeTaxInfoServiceImpl.class);

	@Autowired
	private TaxIncomeTaxInfoDao taxIncomeTaxInfoDao;

   	/**
	 * 新增数据 
     * @param inTaxIncomeTaxInfoVo
     * @return 
	 */
	public int insertTaxIncomeTaxInfo(TaxIncomeTaxInfoVO inTaxIncomeTaxInfoVo) {
		logger.debug("当前新增数据为:"+ inTaxIncomeTaxInfoVo.toString());
		int num = 0;
		try {
			TaxIncomeTaxInfo taxIncomeTaxInfo = new TaxIncomeTaxInfo();
			beanCopy(inTaxIncomeTaxInfoVo, taxIncomeTaxInfo);
			num = taxIncomeTaxInfoDao.insertTaxIncomeTaxInfo(taxIncomeTaxInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

    /**
	 * 根据主键删除信息 
	 * @param inTaxIncomeTaxInfoVo
 	 * @return
	 */
	public int deleteByPk(TaxIncomeTaxInfoVO inTaxIncomeTaxInfoVo) {
		logger.debug("当前删除数据条件为:"+ inTaxIncomeTaxInfoVo);
		int num = 0;
		try {
			TaxIncomeTaxInfo taxIncomeTaxInfo = new TaxIncomeTaxInfo();
			beanCopy(inTaxIncomeTaxInfoVo, taxIncomeTaxInfo);
			num = taxIncomeTaxInfoDao.deleteByPk(taxIncomeTaxInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxIncomeTaxInfoVo +"删除的数据条数为"+ num);
		return num;
	}


    /**
	 * 根据主键更新信息 
	 * @param inTaxIncomeTaxInfoVo
	 * @return 
	 */  
	public int updateByPk(TaxIncomeTaxInfoVO inTaxIncomeTaxInfoVo) {
		logger.debug("当前修改数据为:"+ inTaxIncomeTaxInfoVo.toString());
		int num = 0;
		try {
			TaxIncomeTaxInfo taxIncomeTaxInfo = new TaxIncomeTaxInfo();
			beanCopy(inTaxIncomeTaxInfoVo, taxIncomeTaxInfo);
			num = taxIncomeTaxInfoDao.updateByPk(taxIncomeTaxInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxIncomeTaxInfoVo +"修改的数据条数为"+ num);
		return num;
	}
	
    /**
	 * 根据主键查询详情 
	 * @param taxIncomeTaxInfo
	 * @return 
	 */
	public TaxIncomeTaxInfoVO queryByPk(TaxIncomeTaxInfoVO inTaxIncomeTaxInfoVo) {
		
		logger.debug("当前查询参数信息为:"+ inTaxIncomeTaxInfoVo);
		try {
			TaxIncomeTaxInfo queryTaxIncomeTaxInfo = new TaxIncomeTaxInfo();
			beanCopy(inTaxIncomeTaxInfoVo, queryTaxIncomeTaxInfo);
			TaxIncomeTaxInfo queryRslTaxIncomeTaxInfo = taxIncomeTaxInfoDao.queryByPk(queryTaxIncomeTaxInfo);
			if (Objects.nonNull(queryRslTaxIncomeTaxInfo)) {
				TaxIncomeTaxInfoVO outTaxIncomeTaxInfoVo = beanCopy(queryRslTaxIncomeTaxInfo, new TaxIncomeTaxInfoVO());
				logger.debug("当前查询结果为:"+ outTaxIncomeTaxInfoVo.toString());
				return outTaxIncomeTaxInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


    /**
	 * 一级数据权限 
	 * @param taxIncomeTaxInfo
	 * @return 
	 */	
	@SuppressWarnings("unchecked")
	public List<TaxIncomeTaxInfoVO> queryAllByLevelOne(TaxIncomeTaxInfoVO taxIncomeTaxInfoVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<TaxIncomeTaxInfoVO> list = null;
		try {
			List<TaxIncomeTaxInfo> taxIncomeTaxInfos = taxIncomeTaxInfoDao.queryAllByLevelOneByPage(taxIncomeTaxInfoVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:"+ taxIncomeTaxInfos.size());
			pageSet(taxIncomeTaxInfos, taxIncomeTaxInfoVo);
			list = (List<TaxIncomeTaxInfoVO>) beansCopy(taxIncomeTaxInfos, TaxIncomeTaxInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<TaxIncomeTaxInfoVO> queryAllByLmtApplySeq(TaxIncomeTaxInfoVO taxIncomeTaxInfoVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<TaxIncomeTaxInfoVO> list = null;
		try {
			List<TaxIncomeTaxInfo> taxIncomeTaxInfos = taxIncomeTaxInfoDao.queryAllByLmtApplySeq(taxIncomeTaxInfoVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:"+ taxIncomeTaxInfos.size());
			pageSet(taxIncomeTaxInfos, taxIncomeTaxInfoVo);
			list = (List<TaxIncomeTaxInfoVO>) beansCopy(taxIncomeTaxInfos, TaxIncomeTaxInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 二级数据权限 
	 * @param taxIncomeTaxInfo
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxIncomeTaxInfoVO> queryAllByLevelTwo(TaxIncomeTaxInfoVO taxIncomeTaxInfoVo) {
		logger.debug("查看当前用户及所属机构对应的数据信息的参数信息为:");
		List<TaxIncomeTaxInfo> taxIncomeTaxInfos = taxIncomeTaxInfoDao.queryAllByLevelTwoByPage(taxIncomeTaxInfoVo);
		logger.debug("查看当前用户及所属机构对应的数据信息的结果集数量为:"+taxIncomeTaxInfos.size());
		List<TaxIncomeTaxInfoVO> list = null;
		try {
			pageSet(taxIncomeTaxInfos, taxIncomeTaxInfoVo);
			list = (List<TaxIncomeTaxInfoVO>) beansCopy(taxIncomeTaxInfos, TaxIncomeTaxInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 三级数据权限 
	 * @param taxIncomeTaxInfo
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxIncomeTaxInfoVO> queryAllByLevelThree(TaxIncomeTaxInfoVO taxIncomeTaxInfoVo) {
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的参数信息为:");
		List<TaxIncomeTaxInfo> taxIncomeTaxInfos = taxIncomeTaxInfoDao.queryAllByLevelThreeByPage(taxIncomeTaxInfoVo);
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的结果集数量为:"+ taxIncomeTaxInfos.size());
		List<TaxIncomeTaxInfoVO> list = null;
		try {
			pageSet(taxIncomeTaxInfos, taxIncomeTaxInfoVo);
			list = (List<TaxIncomeTaxInfoVO>) beansCopy(taxIncomeTaxInfos, TaxIncomeTaxInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 四级数据权限  
	 * @param taxIncomeTaxInfo
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxIncomeTaxInfoVO> queryAllByLevelFour(TaxIncomeTaxInfoVO taxIncomeTaxInfoVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<TaxIncomeTaxInfo> taxIncomeTaxInfos = taxIncomeTaxInfoDao.queryAllByLevelFourByPage(taxIncomeTaxInfoVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ taxIncomeTaxInfos.size());
		List<TaxIncomeTaxInfoVO> list = null;
		try {
			pageSet(taxIncomeTaxInfos, taxIncomeTaxInfoVo);
			list = (List<TaxIncomeTaxInfoVO>) beansCopy(taxIncomeTaxInfos, TaxIncomeTaxInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 五级数据权限  
	 * @param taxIncomeTaxInfo
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxIncomeTaxInfoVO> queryAllByLevelFive(TaxIncomeTaxInfoVO taxIncomeTaxInfoVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<TaxIncomeTaxInfo> taxIncomeTaxInfos = taxIncomeTaxInfoDao.queryAllByLevelFiveByPage(taxIncomeTaxInfoVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ taxIncomeTaxInfos.size());
		List<TaxIncomeTaxInfoVO> list = null;
		try {
			pageSet(taxIncomeTaxInfos, taxIncomeTaxInfoVo);
			list = (List<TaxIncomeTaxInfoVO>) beansCopy(taxIncomeTaxInfos, TaxIncomeTaxInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}
	
	/**
     * 
     * TODO 根据证件类型和证件号码查找客户的收入信息<br>
     * @author wanglihua
     * @since 2019年5月8日 下午2:20:19
     * @date 2019年5月8日 下午2:20:19
     * @version 0.1
     */
	@SuppressWarnings("unchecked")
	@Override
	public List<TaxIncomeTaxInfoVO> queryIncome(TaxIncomeTaxInfoVO taxIncomeTaxInfoVO) {
		logger.info("当前查询参数信息为:"+ taxIncomeTaxInfoVO);
		List<TaxIncomeTaxInfoVO> list = null;
		try {
			TaxAgainstLawInfo queryTaxAgainstLawInfos = beanCopy(taxIncomeTaxInfoVO, new TaxAgainstLawInfo());
			List<TaxAgainstLawInfo> queryRs = taxIncomeTaxInfoDao.queryIncome(queryTaxAgainstLawInfos);
			list = (List<TaxIncomeTaxInfoVO>) beansCopy(queryRs, TaxIncomeTaxInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}
	/**
     * 根据授信流水号查询时间最大的收入纳税信息表信息
     * 
     * @author weijj
     * @since 2019年5月29日 上午9:56:08
     * @version 1.0
     */
	@Override
	public TaxIncomeTaxInfoVO queryMaxTaxIncomeTaxInfoBycrdtAppFlowNo(TaxIncomeTaxInfoVO taxIncomeTaxInfo) {
		// TODO Auto-generated method stub
		logger.debug("当前查询参数信息为:"+ taxIncomeTaxInfo);
		try {
			TaxIncomeTaxInfo queryTaxIncomeTaxInfo = new TaxIncomeTaxInfo();
			beanCopy(taxIncomeTaxInfo, queryTaxIncomeTaxInfo);
			TaxIncomeTaxInfo queryRslTaxIncomeTaxInfo = taxIncomeTaxInfoDao.queryMaxTaxIncomeTaxInfoBycrdtAppFlowNo(queryTaxIncomeTaxInfo);
			if (Objects.nonNull(queryRslTaxIncomeTaxInfo)) {
				TaxIncomeTaxInfoVO outTaxIncomeTaxInfoVo = beanCopy(queryRslTaxIncomeTaxInfo, new TaxIncomeTaxInfoVO());
				logger.debug("当前查询结果为:"+ outTaxIncomeTaxInfoVo.toString());
				return outTaxIncomeTaxInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 
	 * TODO 查询扣缴义务人识别号<br>
	 * @author wanglihua
	 * @since 2019年7月1日 下午3:06:03
	 * @date 2019年7月1日 下午3:06:03
	 * @version 0.1 
	 */
	@Override
	public TaxIncomeTaxInfoVO queryWthldngAgntNo(TaxIncomeTaxInfoVO taxIncomeTaxInfoVO) {
		logger.debug("当前查询参数信息为:"+ taxIncomeTaxInfoVO);
		try {
			TaxIncomeTaxInfo queryTaxIncomeTaxInfo = new TaxIncomeTaxInfo();
			beanCopy(taxIncomeTaxInfoVO, queryTaxIncomeTaxInfo);
			TaxIncomeTaxInfo queryRslTaxIncomeTaxInfo = taxIncomeTaxInfoDao.queryWthldngAgntNo(queryTaxIncomeTaxInfo);
			if (Objects.nonNull(queryRslTaxIncomeTaxInfo)) {
				TaxIncomeTaxInfoVO outTaxIncomeTaxInfoVo = beanCopy(queryRslTaxIncomeTaxInfo, new TaxIncomeTaxInfoVO());
				logger.debug("当前查询结果为:"+ outTaxIncomeTaxInfoVo.toString());
				return outTaxIncomeTaxInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	
}
